package com.sgb.kjwl.viewmodel.self;

import android.app.Application;
import android.content.Context;

import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.MutableLiveData;

import com.sgb.kjwl.api.NewAPIManager;
import com.sgb.kjwl.model.entity.MyCarInfoEntity;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.dialog.DialogHelper;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class MyCarInfoModel extends AndroidViewModel {
    public MutableLiveData<MyCarInfoEntity> driverDwtail  = new MutableLiveData<>();
    public MyCarInfoModel(@NonNull Application application) {
        super(application);
    }
    public void getJingDriverDetail(Context context,long no){
        DialogHelper.showProgressDialog(context, null, "加载中", 0, true, null).setCanceledOnTouchOutside(false);
        NewAPIManager.getInstance().getLogisticsAPI().getJingDriverDetail(no).enqueue(new Callback<BaseEntity<MyCarInfoEntity>>() {
            @Override
            public void onResponse(Call<BaseEntity<MyCarInfoEntity>> call, Response<BaseEntity<MyCarInfoEntity>> response) {
                DialogHelper.dismissProgressDialog();

                if (response.body() == null) return;

                if (response.body().getState().equals("ok")) {
                    driverDwtail.postValue(response.body().getData());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<MyCarInfoEntity>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });

    }

}
